package fr.uniscol.dao.impl;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;

import fr.uniscol.dao.IStructureDao;
import fr.uniscol.model.AnneeScolaire;
import fr.uniscol.model.Enseignant;
import fr.uniscol.model.Structure;

public class StructureDaoImpl implements IStructureDao {

	private SessionFactory sessionFactory;
	
	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}

	public List<Structure> getStructures(AnneeScolaire annee, Enseignant enseignant) {
		return null;
	}

	public List<Structure> getAllStructures(AnneeScolaire annee) {

		Session session = sessionFactory.getCurrentSession();
		
		Query q = session.createQuery("From Structure Where annee_id=:annee_id");
		q.setParameter("annee_id", annee.getId());
		
		return q.list();
	}

	public void enregistrerStructure(AnneeScolaire annee, Structure structure) {
		
		Session session = sessionFactory.getCurrentSession();
		
		session.saveOrUpdate(structure);
	}
}
